package vcp.gui.forms;

import javax.swing.JPanel;

import javax.swing.ButtonGroup;
import javax.swing.JRadioButton;

import vcp.gui.components.VCPPanel;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;

/**
 * Check In Widget Form
 *
 */
public class CheckInWidgetForm extends JPanel implements ActionListener{
    
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private VCPPanel buttonPanel;
	private JRadioButton regularbtn;
	private JRadioButton subscribedbtn;	
	private VCPPanel widgetPanel;
	private CheckInSubscriberForm checkInSubscriberForm;
	private CheckInRegularForm checkinRegularForm;

	/**
	 * Create the panel.
	 * @param model 
	 */
	public CheckInWidgetForm() {
		widgetPanel = new VCPPanel();
		checkInSubscriberForm = new CheckInSubscriberForm();
		checkinRegularForm = new CheckInRegularForm();
		widgetPanel.setLayout(new BorderLayout(0, 0));
		widgetPanel.add(checkinRegularForm,BorderLayout.CENTER);
		setLayout(new BorderLayout(0, 0));
		add(getButtonPanel(),BorderLayout.PAGE_START);
		add(widgetPanel,BorderLayout.CENTER);
	}
	
	
	public VCPPanel getButtonPanel(){
    	if(buttonPanel==null){
    		buttonPanel = new VCPPanel(new GridLayout(1, 1));
    		buttonPanel.setBackground(Color.white);
    		regularbtn = new JRadioButton("Regular");
    		regularbtn.setBackground(Color.white);
    		regularbtn.setMnemonic(KeyEvent.VK_R);
    		regularbtn.setActionCommand("RS");
    		regularbtn.setSelected(true);

    		subscribedbtn = new JRadioButton("Subscribed");
    		subscribedbtn.setBackground(Color.white);
    		subscribedbtn.setMnemonic(KeyEvent.VK_S);
    		subscribedbtn.setActionCommand("SS");
    		subscribedbtn.setSelected(false);

    	
    		regularbtn.addActionListener(this);
    		subscribedbtn.addActionListener(this);
    	
    		ButtonGroup btngroup = new ButtonGroup();
    		btngroup.add(regularbtn);
    		btngroup.add(subscribedbtn);

    		buttonPanel.add(regularbtn);
    		buttonPanel.add(subscribedbtn);
    	}
       return buttonPanel;
   }


	public CheckInSubscriberForm getCheckInSubscriberForm() {
		return checkInSubscriberForm;
	}


	public void setCheckInSubscriberForm(CheckInSubscriberForm checkInSubscriberForm) {
		this.checkInSubscriberForm = checkInSubscriberForm;
	}


	public CheckInRegularForm getCheckinRegularForm() {
		return checkinRegularForm;
	}


	public void setCheckinRegularForm(CheckInRegularForm checkinRegularForm) {
		this.checkinRegularForm = checkinRegularForm;
	}


	@Override
	public void actionPerformed(ActionEvent arg) {
		String cmd = arg.getActionCommand();
		widgetPanel.removeAll();
		widgetPanel.repaint();
		if(cmd.equals("SS")){			
			widgetPanel.add(checkInSubscriberForm,BorderLayout.CENTER);
		}else if(cmd.equals("RS")){
			widgetPanel.add(checkinRegularForm,BorderLayout.CENTER);
		}
		
		widgetPanel.getParentFrame().pack();
	}

	
}
